<%@ page import="cn.fl.framework.base.context.CurrentThreadContext" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%request.setAttribute("currentRoleId", CurrentThreadContext.getCurrentRoleId());%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>逾期催收列表 任务分配</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">任务人</div>
                    <div class="field">
                        <input name="usrNm" id="usrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同编号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">逾期天数</div>
                    <div class="field">
                        <input ligerui="width: 82" name="ovdDaysMin" id="ovdDaysMin" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 82" name="ovdDaysMax" id="ovdDaysMax" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">应收日期</div>
                    <div class="field">
                        <input ligerui="width: 83" name="ovdDtMin" id="ovdDtMin" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 83" name="ovdDtMax" id="ovdDtMax" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">逾期金额</div>
                    <div class="field">
                        <input ligerui="width: 83" name="ovdAmtMin" id="ovdAmtMin" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 83" name="ovdAmtMax" id="ovdAmtMax" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">分配状态</div>
                    <div class="field">
                        <input name="allocationFlag" id="allocationFlag" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox" id="searchPrjTypCdId">
                    <div class="label">项目类型</div>
                    <div class="field">
                        <select name="prjTypCd"  id="prjTypCd" >
                            <option value="" selected="selected">请选择</option>
                            <c:forEach items="${projectTypeList}" var="opt">
                                <option value="${opt.key}">${opt.value}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="fieldBox col_33" id="searchInsCodeId">
                    <div class="label">第三方机构</div>
                    <div class="field">
                        <select name="insCode"  id="insCode" >
                            <option value="" selected="selected">请选择</option>
                            <c:forEach items="${friBaseList}" var="fri">
                                <option value="${fri.insCode}">${fri.fundRasInsNm}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">最高逾期期次</div>
                    <div class="field">
                        <input name="maxPd" id="maxPd" type="text" class="ui-textbox" value="" validate="{digits:true,min:1,max:100}">
                    </div>
                </div>
                <div class="fieldBox" id="tableSearchBox">
                    <div class="label">贷款业务类型</div>
                    <div class="field">
                        <select name="tableNm" id="tableNm">
                            <option value="">请选择</option>
                            <option value="MCR_BILL_M">小贷业务</option>
                            <option value="PBL_BILL_M">垫款业务</option>
                            <option value="OTHERS">租赁业务</option>
                        </select>
                    </div>
                </div>


                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                     <sys:funcAuth resCd="taskAssignNewAssignBtn">
                        <span id="assignTaskBtn" class="sq-button sq-button-round">分配</span>
                     </sys:funcAuth>
                    <sys:funcAuth resCd="taskAssignNewBackBtn">
                        <span id="backTaskBtn" class="sq-button sq-button-round">退回</span>
                    </sys:funcAuth>
                    <sys:funcAuth resCd="taskAssignshortBtn">
                       <span id="shortTaskBtn" class="sq-button sq-button-round">短账龄分配</span>
                    </sys:funcAuth>
                    <sys:funcAuth resCd="taskAssignLongBtn">
                       <span id="longTaskBtn" class="sq-button sq-button-round">中长账龄分配</span>
                    </sys:funcAuth>
                </div>
                <div class="clearFix"></div>

            </div>
        </form>
    </div>

    <div id="ligergrid1" class="sq-grid"></div>

</div>

<script type="text/javascript">
    var grid = null, form = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risknew/rskUsrOrgR/initOvdList.do?queryType=2',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 150, align: 'left', enabledSort: false},
                {display: '逾期合同数', name: 'ovdCntQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期支付表数', name: 'ovdPayQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期天数', name: 'ovdDays', width: 100, align: 'right', enabledSort: false},
                {
                    display: '应收金额(元)', name: 'arAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.arAmt / 100);
                    }
                },
                {
                    display: '逾期金额(元)', name: 'ovdAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '罚息金额(元)', name: 'fineAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fineAmt / 100);
                    }
                },
                {display: '任务人', name: 'usrNm', width: 80, align: 'center', enabledSort: false},
                {
                    display: '操作', width: 350, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="repaymentDtl(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_49"></i>还款明细</a>  ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="overdueDtl(' + rowdata.cstId + ');"><i class="sqBtnIco_50"></i>逾期汇总</a> ' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="qyCommRec(' + rowdata.cstId + ',\'' + rowdata.cstNm + '\');"><i class="sqBtnIco_51"></i>催收记录</a>' +
                                '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="calculator(' + rowdata.cstId+','+ rowdata.arAmt + ',' + rowdata.ovdAmt + ','+rowdata.fineAmt+','+ rowdata.ovdDays +');"><i class="sqBtnIco_51"></i>应收款计算</a>';
                    }
                }
            ],
            pageSize: 50,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            rownumbers: true,  //显示序号
            checkbox: true,
            allowUnSelectRow: true,
            alternatingRow: true,
        });
        grid.setHeight(100);

        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        //是否已分配
        $("#allocationFlag").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        form = $("#searchBar").ligerForm();
        liger.get("buOrgCd").setData(${buOrgCdList});
        liger.get("allocationFlag").setData([{"key":"0","value":"未分配"},{"key":"1","value":"已分配"}]);

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        //分配催收任务
        $("#assignTaskBtn").click(function (event) {
            var currentRoleId = "${currentRoleId }";
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            var existIds =[];
            for (var index in selectedRows) {
                //if(currentRoleId=="10031" || currentRoleId=="10028"){ //催收管理部经理 或者 信审中心总经理
                //    // 只能分配逾期 1-20天的任务
                //    if(selectedRows[index].ovdDays >20){
                //        $.ligerDialog.SQalert({content: "不能分配逾期20天以上的任务", SQ_type: "warning"});
                //        return false;
                //    }
                //}else if(currentRoleId=="1804250003"){
                //    // 贷后风控经理
                //    // 只能分配 20 天以上
                //    if(selectedRows[index].ovdDays <20){
                //        $.ligerDialog.SQalert({content: "不能分配逾期20天以下的任务", SQ_type: "warning"});
                //        return false;
                //    }
                //}
                if(selectedRows[index].usrNm == null || selectedRows[index].usrNm == ''){
                    _ids.push(selectedRows[index].cstId);
                }else{
                    existIds.push(selectedRows[index].cstId);
                }
            }
            if(existIds.length > 0){
                $.ligerDialog.SQalert({content: "请选择没有任务人的数据进行分配操作.", SQ_type: "warning"});
                return ;
            }
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            $.ligerDialog.SQopen({
                width: 650,
                height: 500,
                title: '分配任务',
                url: '<%=path%>/risknew/rskUsrCstR/toListPage.do',
                buttons: [
                    {
                        text: "关闭", onclick: onCancel, type: 'cancel'
                    }
                ],
                data: {ids: _ids},
            });

        });
        // 短账龄分配
        $("#shortTaskBtn").click(function(event){
            parent.parent.mainApp.f_addTab('tab_rsk_short_task','短账龄分配','<%=path%>/risknew/rskUsrCstR/autoAssign/toMoneyInput.do?age=0');
        });
        // 中长账龄分配
        // $("#longTaskBtn").click(function(event){
            <%--parent.parent.mainApp.f_addTab('tab_rsk_long_task','中长账龄分配','<%=path%>/risknew/rskUsrCstR/autoAssign/toMoneyInput.do?age=1');--%>
        // });
        $("#longTaskBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            var existIds =[];
            for (var index in selectedRows) {
                if(selectedRows[index].usrNm == null || selectedRows[index].usrNm == ''){
                    _ids.push(selectedRows[index].cstId);
                }else{
                    existIds.push(selectedRows[index].cstId);
                }
            }
            if(existIds.length > 0){
                $.ligerDialog.SQalert({content: "请选择没有任务人的数据进行分配操作.", SQ_type: "warning"});
                return ;
            }
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            $.ligerDialog.SQopen({
                width: 650,
                height: 500,
                title: '分配任务',
                url: '<%=path%>/risknew/rskUsrCstR/toListPage.do?age=1',
                buttons: [
                    {
                        text: "关闭", onclick: onCancel, type: 'cancel'
                    }
                ],
                data: {ids: _ids},
            });

        });
    });

    //退回催收任务
    $("#backTaskBtn").click(function (event) {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length == 0) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }
        var _ids = [];
        for (var index in selectedRows) {
            if(selectedRows[index].usrNm != null && selectedRows[index].usrNm != ''){
                _ids.push(selectedRows[index].cstId);
            }
        }
        if(_ids.length == 0){
            $.ligerDialog.SQalert({content: "请选择正确的数据进行退回操作.", SQ_type: "warning"});
            return ;
        }
        var data = JSON.stringify(_ids);
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {"ids":data},
            url: '<%=path%>/risknew/rskUsrCstR/removeByIds.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    grid.reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

    });
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    /* 还款明细 */
    function repaymentDtl(cstId, cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '还款明细',
            url: '<%=path%>/risk/overdueCollect/toCstCapFundListPage.do?cstId=' + cstId + "&cstNm=" + cstNm,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }
    /* 逾期汇总 */
    function overdueDtl(cstId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '逾期明细',
            url: '<%=path%>/capital/capOverdueInfo/toOverdueDtl.do?cstId=' + cstId,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }
    //查询催收记录
    function qyCommRec(_cstId, _cstNm) {
        parent.parent.mainApp.f_addTab('rsk_cmm_rec'+_cstId,'催收记录','<%=path%>/risknew/rskCommRecNew/toListPage.do?cstId='+_cstId+'&&cstNm='+ _cstNm);
    }
    /**
     * 应收款计算
     **/
    function calculator(cstId,arAmt,ovdAmt,fineAmt,ovdDay){
        $.ligerDialog.open({
            width: 450,
            height: 280,
            title: '应付金额计算',
            url: '<%=path%>/risk/overdueCollect/toCalculator.do?arAmt='+arAmt + '&ovdAmt='+ovdAmt + '&fineAmt='+ fineAmt + '&ovdDay=' +ovdDay+"&cstId="+cstId,
        });
    }
</script>

</body>
</html>
